<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/4/28
 * Time: 下午5:27
 */

namespace App\Busi\Modules\Resource;


use App\Busi\Modules\BaseBusi;
use App\Http\Requests\RandNewsListRo;
use App\Models\News;
use Illuminate\Support\Facades\Cache;

class RandNewsListBusi extends BaseBusi
{
    public function handle(RandNewsListRo $ro)
    {

        $mem_key = "randnews_list_key";
        if ($data = Cache::get($mem_key)) {
            $data = json_decode($data, true);
            return $data;
        }
        $data = News::where("flag", "=", 1)->select(["id", "title"])->orderBy(\DB::raw('RAND()'))->take(6)->get();
        Cache::put($mem_key, json_encode($data), 60 * 12);
        return $data;
    }
}